<template>
  <div>
    <el-form ref="rulesForm" label-position="top" label-width="130px" :model="form" :rules="rules">
      <p class="hint_">基础信息</p>
      <div class="flex_">
        <el-form-item label="品牌编号：" prop="BRAND_ID">
          <el-input v-model="form.BRAND_ID" :disabled="disabled" />
        </el-form-item>
        <el-form-item label="品牌名称：" prop="BRAND_NAME">
          <el-input v-model="form.BRAND_NAME" />
        </el-form-item>
        <el-form-item label="品牌英文名：">
          <el-input v-model="form.BRAND_NAMEE" />
        </el-form-item>
      </div>
      <div class="flex_">
        <el-form-item label="待定1：">
          <el-input v-model="form.UDF1" />
        </el-form-item>
        <el-form-item label="待定2：">
          <el-input v-model="form.UDF2" />
        </el-form-item>
        <el-form-item label="待定3：">
          <el-input v-model="form.UDF3" />
        </el-form-item>
      </div>
      <!-- <el-form-item label="所属类型：" prop="BRAND_TYPE">
        <el-select v-model="form.BRAND_TYPE" clearable placeholder="请选择">
          <el-option v-for="item in budgetUnit.closed" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="备注：">
        <el-input v-model="form.NOTES" maxlength="500" placeholder="请输入内容" :rows="7" show-word-limit type="textarea" />
      </el-form-item>
      <p class="hint_">其他信息</p>
      <div class="flex_">
        <el-form-item label="创建人员：">
          <el-input v-model="form.ADDWHO" disabled />
        </el-form-item>
        <el-form-item label="创建时间：">
          <el-input v-model="form.ADDTIME" disabled />
        </el-form-item>
        <el-form-item label="编辑人员：">
          <el-input v-model="form.EDITWHO" disabled />
        </el-form-item>
      </div>
      <div class="flex_">
        <el-form-item label="编辑时间：">
          <el-input v-model="form.EDITTIME" disabled />
        </el-form-item>
      </div>
      <div class="footer_">
        <el-form-item>
          <el-button @click="reset">重置</el-button>
          <el-button type="primary" @click="submitForm">提交</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<script>
  import budgetUnit from '../common/options'
  import requestMethod from '../common/requestMethod'
  import publicFn from '../common/requestCommon'
  export default {
    name: 'BrandDialog',
    props: {
      uploadTag: {
        type: String,
        default: '',
      },
      brandOneId: {
        type: String,
        default: '',
      },
    },
    emits: ['success'],
    data() {
      return {
        form: {
          BRAND_ID: '',
          BRAND_NAME: '',
          BRAND_NAMEE: '',
          // BRAND_TYPE: '',
          NOTES: '',
          UDF1: '',
          UDF2: '',
          UDF3: '',
        },
        budgetUnit,
        rules: {
          BRAND_ID: [{ required: true, message: '请输入品牌编号', trigger: 'blur' }],
          BRAND_NAME: [{ required: true, message: '请输入品牌名称', trigger: 'blur' }],
          BRAND_NAMEE: [{ required: true, message: '请输入品牌英文名', trigger: 'blur' }],
          // BRAND_TYPE: [{ required: true, message: '请选择所属类型', trigger: 'change' }],
        },
        tablePage: {
          '#LIMIT#': 1,
          '#PAGE_SIZE#': 9999,
        },
        disabled: false,
      }
    },
    created() {
      if (this.brandOneId) {
        this.lookForm()
        this.disabled = true
      }
    },
    methods: {
      //提交表单
      async submitForm() {
        this.$refs['rulesForm'].validate((valid) => {
          if (valid) {
            this.saveOrEditor()
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      reset() {
        this.form = {
          BRAND_ID: '',
          BRAND_NAME: '',
          BRAND_NAMEE: '',
          BRAND_TYPE: '',
          NOTES: '',
        }
      },
      //编辑回显
      async lookForm() {
        let res = await publicFn(requestMethod.BRAND_ONE, { BRAND_ID: this.brandOneId, ...this.tablePage })
        if (res.code === '00000') {
          this.form = res.data[requestMethod.BRAND_ONE].data[0]
        } else {
          this.$message({
            type: 'info',
            message: res.msg,
          })
        }
      },
      //新增/编辑
      async saveOrEditor() {
        let method = null
        if (this.brandOneId) {
          method = requestMethod.BRAND_EDITOR
        } else {
          method = requestMethod.BRAND_ADD
        }
        let res = await publicFn(method, { ...this.form })
        if (res.code === '00000') {
          this.$emit('success')
        } else {
          this.$message({
            type: 'info',
            message: res.msg,
          })
        }
      },
    },
  }
</script>
<style lang="scss">
  @import '../static/scss/Dialog.scss';
</style>
